import 'package:capsule/utils/callbacks.dart';
import 'package:flutter/material.dart';

import 'form_input.dart';

class FormInputWithIcon extends StatelessWidget {
  final VoidCallbackOneString onSubmitted;
  final TextEditingController controller;
  final String hintText;
  final Icon? icon;
  const FormInputWithIcon(
      {super.key,
      required this.onSubmitted,
      required this.controller,
      this.hintText = "请输入",
      this.icon});
  @override
  Widget build(Object context) {
    BoxDecoration barPanelDecoration = BoxDecoration(
        borderRadius: BorderRadius.circular(5), color: Colors.white);
    return Container(
      padding: const EdgeInsets.fromLTRB(2, 2, 5, 2),
      decoration: barPanelDecoration,
      child: LayoutBuilder(
        builder: (context, constraints) {
          return Row(children: [
            SizedBox(
                width: icon != null
                    ? constraints.maxWidth - 25
                    : constraints.maxWidth,
                child: FormInput(
                  controller: controller,
                  textInputAction: TextInputAction.done,
                  onFieldSubmitted: onSubmitted,
                  fillded: false,
                  hintText: hintText,
                )),
            if (icon != null)
              InkWell(
                  onTap: () {
                    onSubmitted.call(controller.value.text);
                  },
                  child: icon)
          ]);
        },
      ),
    );
  }
}
